﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using EQT.Dal;
using EQT.Model;
using System.Collections.Generic;

/// <summary>
/// 签名文件上传。
/// </summary>
public class UploadSignature : IUploadFile
{
    private DaTuser daUser = DevFuture.Common.WorkContext.AppCtx.GetObject("DaTuser") as DaTuser;
    private DaTfiles datfile = DevFuture.Common.WorkContext.AppCtx.GetObject("DaTfiles") as DaTfiles;

    public UploadSignature()
    {
        
    }

    #region IUploadFile 成员

    public void InitUpload(IUploadPage up, System.Collections.Specialized.NameValueCollection nvc)
    {
        #region 为签名上传附件
        //给定操作员的ID
        string strUid = nvc["UID"];//获取操作员ID号

        if (String.IsNullOrEmpty(strUid) || strUid.Trim().Length == 0)
        {
            Utility.SiteError("缺失所必需的参数【操作员编号】", up.Response);
        }
        else
        {
            up.SetConfigValue("UID", strUid.Trim());
            
            MoTuser mo = new MoTuser();
            mo.Uid = strUid;
            daUser.GetEntityEx(ref mo);

            
            up.SetPageTitle(String.Format("为操作员【{0}：{1}】上传图片签名：",
                mo.Uid,  mo.DisplayName));
        }
        #endregion
    }

    public int Upload1(IUploadPage up, MoTfiles file, string opter_id)
    {
        MoRefFile modref = new MoRefFile();
        modref.Eid = up.GetConfigValue("UID").ToString();
        modref.FileId = file.FileId;
        modref.RfId = SequenceKeys.GenerateReferFileID();

        MoTuser moduser=daUser.GetEntities(" where uid='"+modref.Eid+"'")[0];
        moduser.Signaturepic = modref.FileId;
        try
        {
            return datfile.AddFileSignature(file, modref, moduser);
        }
        catch (DalException de)
        {
            Utility.GlobalLog.Error("添加单个文件失败!", de);
            Utility.SiteError("添加单个文件失败!", up.Response);
            return -1;
        }
    }

    public int UploadedMuliti(IUploadPage up, List<MoTfiles> files, string opter_id)
    {
        throw new Exception("The method or operation is not implemented.");
    }

    public string GetReturnUrl(IUploadPage up)
    {
        return String.Format("notice.aspx?edit&noticeid={0}", up.GetConfigValue("NOTICE_ID"));
    }

    #endregion
}
